<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .goods-ul {
            width: 1000px;
            height: 1100px;
            border: 1px solid rgb(51, 39, 39);
            margin: 0 auto;
            list-style: none;
        }

        .goods-ul li.li1 {
            float: left;
            width: 300px;
            height: 350px;
            margin-left: 25px;
            margin-top: 10px;
            font-size: 14px;
            border: 1px solid black;
        }

        .btn {
            width: 100px;
            height: 30px;
            font-size: 16px;
            margin-bottom: 50px;
        }

        .goods-ul li.li1.active {
            border: 1px solid red;
            box-shadow: 10px 10px 20px 10px pink;
        }
    </style>
</head>

<body>
    <div>
        <ul class="goods-ul"></ul>
    </div>
</body>

</html>

<script src="./jq.js"></script>

<script src="./list.js"></script>
<script>
    $(function () {
        var liStr = '';
        
        var $goodUl = $('.goods-ul');
        $.each(list, function (i, item) {
            var id = item.id;
            var img = item.image;
            liStr += "<li class='li1' sku=" + id + ">" +
                `<a href=./详情页.html?id=${id}><img width='200' src=${img} /></a>` +
                "<div class='name' >" + item.name + "</div>" +
                "<div class='brand' >品牌:" + item.brandName + "</div>" +
                "<div class='price' >" + item.marketPrice + item.unit + "</div>" +
                "<button class='btn'>加购</button>"
            "</li>"
        })
        $goodUl.html(liStr);
       
        $goodUl.on('mouseenter', '.li1', function () {
            $(this).addClass('active');
        })
        $goodUl.on('mouseleave', '.li1', function () {
            $(this).removeClass('active');
        })
        $goodUl.on('click', '.li1', function () {
            var id = $(this).attr('sku');
         
            location.href = './详情页.html?id=' + id;
        })
    })
</script>